//流程审批信息
Jes.flowinfo ={
	//query
	init : function(){
		if(!Jes.getUserSess()) return;
		Jes.cBtn();
		Jes("search").onclick=function(){Jes.flowinfo.query();}
		Jes.val("opporid",Jes.request("opporid"));
		this.query();
	}
	,query : function(){
		Jes.page("flowinfo_query_sql");
	}
	,tsfFlowNodeCol : function(status,value){
		var html;
		if(status=='1') html ='<span style="color:#3d00b9;">'+value+'</span>';//运行中
		else if(status=='2') html ='<span style="color:#d4d0c8;">'+value+'</span>';//完成
		else html ='<span style="color:#ff0000;">'+value+'</span>';//终止
		return html;
	}
}


//商机流程
Jes.flow ={
	//query
	init : function(){
		if(!Jes.getUserSess(1)) return;
		Jes.cBtn();
		Jes("search").onclick=function(){Jes.flow.query();}
		Jes("tj").onclick=function(){Jes.flow.save();}
		var flow=Jes.request("flow"),title;
		Jes.val("flownode",flow);
		if(flow == "1") title="待提交商机";
		else if(flow == "2") title="待派单商机";
		else if(flow=="3") title="待核实商机";
		else if(flow=="4") title="待实施商机";
		else if(flow=="5") title="待完工商机";
		else if(flow=="6") title="待考核商机";
		Jes.html("title",title);
		initTabs('tabView_1',Array(title),0,"100%",90,Array(false));
		this.selFlowUser(flow);//1.获取审批人
		this.query();
	}
	,query : function(){
		Jes.page("opporflow_query_sql",{pageSize:5});
	}
	,selFlowUser : function(flow){
		Jes('_flowadmins').style.height='100%';
		flow=flow?flow:Jes.request("flow");
		var rolebh;
		if(flow == "1") {
			rolebh="flowadmin";//1.待提交，选择流程管理员
			Jes.hide("flow_2");//2.是否同意
			Jes.html("flowinfo","请审核此商机");//3.审批意见
		}else if(flow=="2"){
			Jes.Select.remove('isagree','3');
			rolebh="checkadmin";//1.待派单,选择核实人员
			//Jes.hide("flow_2");//2.是否同意
			Jes.html("flow_2_1","是否有效");//2.是否有效
			//Jes.html("flowinfo","请核实此商机");//3.审批意见
			var isagree = Jes.val('isagree');
			if(isagree=='1'){
				//Jes.html("_flowadmins","<font color='red'>系统自动流转!</font>");
				Jes.val("flowinfo","请核实此商机");//3.审批意见
			}else if(isagree=='2'){//不同意
				Jes.html("_flowadmins","<font color='red'>系统自动回退,并确认商机为无效!</font>");
				Jes.val("flowinfo","此为无效商机");//3.审批意见
				return;
			}
		}else if(flow=="3"){
			rolebh="flowadmin";//1.待核实
			Jes.html("flow_2_1","是否属实");//2.是否核实
			var isagree = Jes.val("isagree");
			if(isagree=="1"){
				Jes.html("_flowadmins","<font color='red'>系统自动流转!</font>");
				Jes.val("flowinfo","此商机属实");//3.审批意见
			}else if(isagree=='2'){//不同意
				Jes.html("_flowadmins","<font color='red'>系统自动回退,并确认商机为无效!</font>");
				Jes.val("flowinfo","此商机不属实");//3.审批意见
			}else{//回退
				Jes.html("_flowadmins","<font color='red'>提交错误，系统自动回退!</font>");
				Jes.val("flowinfo","请换核实人");//3.审批意见
			}
			return;
		}else if(flow=="4"){
			rolebh="impladmin";//1.待实施
			Jes.hide("flow_2");//2.是否同意
			Jes.html("flowinfo","请实施");//3.审批意见
		}else if(flow=="5"){
			//rolebh="flowadmin";//1.待完工
			Jes.html("flow_2_1","是否完工");//2.是否完工
			var isagree = Jes.val("isagree");
			if(isagree=="1"){
				Jes.show('t1','t2','t3');
				Jes.html("_flowadmins","<font color='red'>恭喜商机顺利完工!</font>");
				Jes.val("flowinfo","此商机已经完工");//3.审批意见
			}else if(isagree=='2'){//不同意
				Jes.show('t1','t2'),Jes.hide('t3');
				Jes.html("_flowadmins","<font color='red'>非常遗憾商机无法完成!</font>");
				Jes.val("flowinfo","此商机不能完工");//3.审批意见
			}else{//回退
				Jes.hide('t1','t2','t3');
				Jes.html("_flowadmins","<font color='red'>发错人了，系统自动回退!</font>");
				Jes.val("flowinfo","请换实施人");//3.审批意见
			}
			return;
		}
		Jes.query("roleuser_query_sql",{param:{"rolebh":rolebh}},function(data){
			var html=['<table>'],pro='',deptname='',num=-1,h=0;
			for(var i=0;i<data.length;i++){
				if(i==0) pro ='title="下一环节人员" rule="group" checked',type=flow==4?'checkbox':'radio';
				else pro = '';
				if(deptname != data[i].deptname){
					num++;
					if(num%3==0){
						h++;
						if(deptname=='') html.push('<tr>');
						else html.push('</td></tr><tr>');
					}
					deptname=data[i].deptname;
					html.push('<td><span style="color:#d4d0c8;">'+deptname+'</span>:</td><td>');
				}
				html.push('<input type="'+type+'" id="userid" name="userid" '+pro+' class="checkbox" value="'+data[i].userid+'">'+data[i].username);
			}
			html.push('<span class="notnull">*</span></td></tr></table>');
			if(h>=3) Jes('_flowadmins').style.height='90px';
			Jes.html('_flowadmins',html);
		});
	}
	//流程提交
	,save : function(){
		if(!Jes("userid") && Jes.html('_flowadmins').indexOf('required')!=-1){alert("下一环节人员没有配置!");return;}
		Jes.save("oppor.flow",null,function(data){
			alert(data);
			Jes.flow.query();
		});
	}
	,open : function(type,id){
		switch(type){
			case "opporop":
					_newTab(id?'商机编辑':'商机新增',"opporop.html".J({id:id}));
				break;
			case "opporview":
					_newTab("商机查看","opporview.html?id="+id);
				break;
			case "flowinfo":
					_newTab("流程审批信息","flowinfo.html?opporid="+id);
				break;
		}
	}
}